﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FourKill.Engine;
using System.Resources;
using FourKillEnginePrototype.Properties;
namespace FourKillEnginePrototype
{
    public partial class Main : Form
    {
        private string _userGuid;
        public Main()
        {
            InitializeComponent();
            #region Painters
            //this.firstPersonViewControl21.OverlayPainters.Add(new SpiralEffect(Color.Red, Color.Orange));
            this.firstPersonViewControl21.UnderlayPainters.Add(new Sky());
            this.firstPersonViewControl21.UnderlayPainters.Add(new Ground());

            Color c = Color.Wheat;
            int tileSize = 4;
            for (int x = 20; x < 40; x += tileSize)
            {
                for (int y = 0; y < 800; y += tileSize)
                {
                    if (((x + y) % (tileSize * 2)) == 0) c = Color.Wheat;
                    else c = Color.Tan;

                    this.firstPersonViewControl21.UnderlayPainters.Add(new GroundPolygon(new List<Coordinates3D>
                    {
                        new Coordinates3D(x, y, 0),
                        new Coordinates3D(x-tileSize, y, 0),
                        new Coordinates3D(x-tileSize, y-tileSize, 0),
                        new Coordinates3D(x, y-tileSize, 0)
                    }, c));
                }
            }

            // Follow the yellow brick road...
            this.firstPersonViewControl21.UnderlayPainters.Add(new GroundPolygon(new List<Coordinates3D>
            {
                new Coordinates3D(10, -10, 0),
                new Coordinates3D(30, -10, 0),
                new Coordinates3D(10, -10000, 0),
                new Coordinates3D(30, -10000, 0)
            }, Color.Yellow));

            //this.firstPersonViewControl21.OverlayPainters.Add(new Panels());
            //this.firstPersonViewControl21.OverlayPainters.Add(new Alert());
            this.firstPersonViewControl21.GameObjects.Add(new MistObject(1000, .2));
            #endregion

            AddWanderingPeople();
            //AddCameraMan();
            AddPathMan();
            AddBirds();
            AddVeggies();
            AddClouds();
            AddHouses();
            //DrawCastle();
            JustinTesting();


            //_ws.ClearUserObjectsFromApplicationSession();
            //// Server Side
            //for (int i = 0; i < 100; i++)
            //{
            //    _userGuid = _ws.Validate(r.Next(0, 100).ToString(), "password");
            //    _ws.UpdateCoordinates(r.Next(0, 1000), r.Next(0, 1000), 0, 50, new Guid(_userGuid));
            //}
            //_userGuid = _ws.Validate("george", "password");
            //_ws.UpdateCoordinates(50, 50, 0, 50, new Guid(_userGuid));

            //AddUsers();
            //AddTreeDees();

            this.firstPersonViewControl21.Start();
        }

        #region Random Testing
        Random r = new Random();

        private void JustinTesting()
        {

            #region Boxes
            ThreeDimensionalObject tdo = new ThreeDimensionalObject(
                new List<List<ICoordinates3D>> 
                {
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 0),
                        new Coordinates3D(-10, 10, 0),
                        new Coordinates3D(-10, 10, 20),
                        new Coordinates3D(10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 0),
                        new Coordinates3D(10, -10, 0),
                        new Coordinates3D(10, -10, 20),
                        new Coordinates3D(10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, -10, 0),
                        new Coordinates3D(-10, -10, 0),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(10, -10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(-10, 10, 0),
                        new Coordinates3D(-10, -10, 0),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(-10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 20),
                        new Coordinates3D(-10, 10, 20),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(10, -10, 20)
                    }
                });


            tdo.Height = 20;
            tdo.Width = 20;
            tdo.X = 55;
            tdo.Y = 55;
            tdo.Z = 0;
            //tdo.Texture = Resources.bricks;
            tdo.Color = Color.Blue;
            this.firstPersonViewControl21.GameObjects.Add(tdo);

            tdo = new ThreeDimensionalObject(
                new List<List<ICoordinates3D>> 
                {
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 0),
                        new Coordinates3D(-10, 10, 0),
                        new Coordinates3D(-10, 10, 20),
                        new Coordinates3D(10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 0),
                        new Coordinates3D(10, -10, 0),
                        new Coordinates3D(10, -10, 20),
                        new Coordinates3D(10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, -10, 0),
                        new Coordinates3D(-10, -10, 0),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(10, -10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(-10, 10, 0),
                        new Coordinates3D(-10, -10, 0),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(-10, 10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 20),
                        new Coordinates3D(-10, 10, 20),
                        new Coordinates3D(-10, -10, 20),
                        new Coordinates3D(10, -10, 20)
                    },
                    new List<ICoordinates3D> {
                        new Coordinates3D(10, 10, 0),
                        new Coordinates3D(-10, 10, 0),
                        new Coordinates3D(-10, -10, 0),
                        new Coordinates3D(10, -10, 0)
                    }
                });
            tdo.Height = 20;
            tdo.Width = 20;
            tdo.X = -55;
            tdo.Y = -55;
            tdo.Z = 50;
            tdo.Color = Color.Red;
            this.firstPersonViewControl21.GameObjects.Add(tdo);

            #endregion
        }

        private void AddWanderingPeople()
        {
            //Wandering People
            for (int i = 0; i < 500; i++)
            {
                int size = r.Next(6, 12);
                WanderingPersonGameObject person = new WanderingPersonGameObject();
                person.Bearing = Utility.Radians(r.Next(0, 359));
                person.Height = person.Sprite.SpriteSheet.HeightToWidthRatio * size;
                person.Width = size;
                person.X = r.Next(-1000, 1000);
                person.Y = r.Next(-1000, 1000);
                person.CollisionArea = new Size(32, 32);
                this.firstPersonViewControl21.GameObjects.Add(person);
            }
        }

        private void AddCameraMan()
        {
            int s = r.Next(6, 12);
            WanderingPersonGameObject cameraPerson = new WanderingPersonGameObject();
            cameraPerson.Bearing = Utility.Radians(r.Next(0, 359));
            cameraPerson.Height = cameraPerson.Sprite.SpriteSheet.HeightToWidthRatio * s;
            cameraPerson.Width = s;
            cameraPerson.X = r.Next(-1000, 1000);
            cameraPerson.Y = r.Next(-1000, 1000);
            cameraPerson.CollisionArea = new Size(32, 32);

            this.firstPersonViewControl21.GameObjects.Add(cameraPerson);
            firstPersonViewControl21.Camera.Attach(cameraPerson);
        }

        private void AddPathMan()
        {
            List<Coordinates3D> path = new List<Coordinates3D>();
            path.Add(new Coordinates3D(0, 0, 0));
            //for (int i = 0; i < 100; i++)
            //{
            //    path.Add(new Coordinates3D(r.Next(0, 200), r.Next(0, 200), 0));
            //}
            path.Add(new Coordinates3D(10, 0, 0));
            path.Add(new Coordinates3D(10, 10, 0));
            path.Add(new Coordinates3D(0, 10, 0));
            path.Add(new Coordinates3D(0, 0, 0));

            PathPersonObject pathPerson = new PathPersonObject(path);
            pathPerson.Bearing = Utility.Radians(r.Next(0, 359));
            pathPerson.Height = pathPerson.Sprite.SpriteSheet.HeightToWidthRatio * 6;
            pathPerson.Width = 6;
            pathPerson.X = r.Next(0, 0);
            pathPerson.Y = r.Next(0, 0);
            pathPerson.CollisionArea = new Size(32, 32);

            this.firstPersonViewControl21.GameObjects.Add(pathPerson);
            //firstPersonViewControl21.Camera.Attach(pathPerson);
        }

        private void AddBirds()
        {
            // Birds
            for (int i = 0; i < 150; i++)
            {
                FlyingBirdObject bird = new FlyingBirdObject();
                bird.Bearing = Utility.Radians(r.Next(0, 359));
                bird.Height = r.Next(2, 4);
                bird.Width = bird.Height;
                bird.X = r.Next(-1000, 1000);
                bird.Y = r.Next(-1000, 1000);
                this.firstPersonViewControl21.GameObjects.Add(bird);
            }
        }

        private void AddClouds()
        {
            // Clouds
            for (int i = 0; i < 25; i++)
            {
                CloudObject cloud = new CloudObject();
                cloud.Height = r.Next(50, 300);
                cloud.Width = cloud.Height * 2;
                cloud.X = r.Next(-1800, 1800);
                cloud.Y = r.Next(-1800, 1800);
                cloud.Speed = r.NextDouble() * .04;
                cloud.Z = r.Next(400, 600);
                this.firstPersonViewControl21.GameObjects.Add(cloud);
            }
        }

        private void AddVeggies()
        {

            // Vegitation
            for (int j = 0; j < 500; j++)
            {
                int size = r.Next(15, 70);
                TreeObject tree = new TreeObject(TreeObject.TreeTypes.FourTriangle)
                {
                    Width = size,
                    Height = size,
                    X = r.Next(-3600, 3600),
                    Y = r.Next(-3600, 3600),
                    Bearing = Utility.Radians(r.Next(0, 180))
                };
                this.firstPersonViewControl21.GameObjects.Add(tree);
            }

            // Vegitation
            for (int j = 0; j < 500; j++)
            {
                int size = r.Next(15, 70);
                TreeObject tree = new TreeObject(TreeObject.TreeTypes.Simple)
                {
                    Width = size,
                    Height = size,
                    X = r.Next(-3600, 3600),
                    Y = r.Next(-3600, 3600),
                    Bearing = Utility.Radians(r.Next(0, 180))
                };
                this.firstPersonViewControl21.GameObjects.Add(tree);
            }
        }

        private void AddHouses()
        {
            // Houses
            for (int j = 0; j < 25; j++)
            {
                HouseObject house = new HouseObject
                {
                    Width = 30,
                    Height = 30 * .69,
                    X = r.Next(-1800, 1800),
                    Y = r.Next(-1800, 1800),
                    Bearing = Utility.Radians(r.Next(0, 180))
                };
                this.firstPersonViewControl21.GameObjects.Add(house);
            }
        }

        #endregion
    }
}
